//
//  InfoMgr.m
//  AirTicket
//
//  Created by imac.bmw on 11-1-4.
//  Copyright 2011 aircococ. All rights reserved.
//

#import "InfoMgr.h"
#import "CellNeedData.h"

@implementation InfoMgr
@synthesize dataList;

-(void)loadDataList
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo.plist"];
	NSFileManager *fM=[NSFileManager defaultManager];
	if(![fM fileExistsAtPath:accountFilename])
	{
		self.dataList = [NSMutableDictionary dictionary];
	}
	else
	{
		self.dataList = [NSMutableDictionary dictionaryWithContentsOfFile:accountFilename];
	}
}

-(void)saveDataList
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo.plist"];
	[self.dataList writeToFile:accountFilename atomically:YES];
	
}

-(void)saveData:(id)data forKey:(NSString *)key {

	[self.dataList setObject:data forKey:key];
	[self saveDataList];
}

-(id)getDataForKey:(NSString *)key {
	
	id object = [self.dataList objectForKey:key];

	return object;
}

-(void)dealloc
{
	[self.dataList release];
	[super dealloc];
}

@end
